<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>大家都在看</title>
    <#include "../common/header.ftl"/>

    <script type="text/javascript">
        $(function () {
            $('.inputBtn').click(function () {
                //
                $('#editForm input[name="strategyName"]').val($('#strategyId option:selected').html())
                var strategyId = $('#strategyId option:selected').val();
                if(strategyId == -1){
                    $.messager.alert("温馨提示","添加关联前请先选择攻略");
                    return;
                }
                $.get('/strategyTravel/getRetionTravelByStrategyId.do',{strategyId:strategyId},function (data) {
                    var html="<option value='-1'>请选择关联游记</option>";
                    $.each(data,function (index, value) {
                        html += "<option value='"+ value.id +"'>"+ value.title +"</option>"
                    });
                    $('#travelId').html(html);
                });

                $('#editModal').modal('show');
            });
            // 编辑保存提交表单
            $('.btn_submit').click(function () {
                // 提交前将攻略id携带到服务器
                $('#editForm input[name="strategyId"]').val( $('#strategyId').val());
                $('#editForm').ajaxSubmit(function (data) {
                    if (data.success) {
                        window.location.href = '/strategyTravel/list.do';
                    } else {
                        $.messager.alert("温馨提示", data.msg);
                    }
                });

            });
        });
    </script>

</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
		<#assign currentMenu = "strategyTravel" />
				<#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="page-header">
                <h3>大家都在看</h3>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/strategyTravel/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                        <label>攻略搜索</label>
                        <select name="strategyId" id="strategyId" class="form-control">
                            <option value="-1">请选择攻略</option>
                                <#list strategies as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                        </select>
                        <script>
                            $('#strategyId').val(${strategyId!});
                        </script>
                    </div>
                    <div class="form-group">
                        <button id="query" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                        <button type="button" class="btn btn-success inputBtn"><i class="icon-plus"></i> 添加关联</button>
                    </div>
                </form>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>关联游记</th>
                    </tr>
                    </thead>
                    <tbody>
                    <#list list as vo>
                    <tr>
                        <td>${vo.title!}</td>
                        <td>
                            <a href="/travel/releaseList.do?travelId=${vo.id}" target="_blank" class="btn btn-success inputBtn" >查看游记文章</a></td>
                        <td>
                            <a href="/strategyTravel/delete.do?travelId=${vo.id}&strategyId=${strategyId!}" class="btn btn-danger">删除</a>
                        </td>
                    </tr>
                    </#list>
                    </tbody>
                </table>

            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑/添加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyTravel/save.do" method="post" id="editForm">
                    <input type="hidden" name="strategyId"/>
                    <div class="form-group" id="parentDiv">
                        <label class="col-sm-3 control-label">所属攻略：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="strategyName" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">关联游记 ：</label>
                        <div class="col-sm-6">
                            <select name="travelId" id="travelId" class="form-control">
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_submit">保存</button>
                <button type="button" class="btn btn-danger" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>